﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Mail;
using TCHSHue.BLL;
using System.Net;
using System.Configuration;
using System.Web.Configuration;
using System.Net.Configuration;
namespace TCHSHue.Modules.AdminControl.DangNhap
{
    public partial class ctrQuenMatKhau : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void bntGoi_Click(object sender, EventArgs e)
        {
            var us = UserBLL.searchEmail(txtEmail.Text.Trim());
            if (us != null)
            {
                Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
                var mailSetting = config.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;
                var smtp = new System.Net.Mail.SmtpClient();
                {
                    smtp.Host = mailSetting.Smtp.Network.Host; //"smtp.gmail.com";
                    smtp.Port = mailSetting.Smtp.Network.Port;//587;
                    smtp.EnableSsl = mailSetting.Smtp.Network.DefaultCredentials;// true;
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.Credentials = new NetworkCredential(mailSetting.Smtp.From, mailSetting.Smtp.Network.Password /*"vpcgcndathue@gmail.com", "12345hue"*/);
                    smtp.Timeout = 20000;
                }
                // Passing values to smtp object
                smtp.Send(mailSetting.Smtp.From, txtEmail.Text.Trim(), "Thông báo", "Mật khẩu của bạn là: " + us.matKhau);
                thongBao.Visible = true;
                loiEmail.Visible = false;
            }
            else
            {
                loiEmail.Visible = true;
                thongBao.Visible = false;
            }
        }
    }
}